<?php
/**
 * TomatoCMS
 * 
 * LICENSE
 *
 * This source file is subject to the GNU GENERAL PUBLIC LICENSE Version 2 
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://www.gnu.org/licenses/gpl-2.0.txt
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@tomatocms.com so we can send you a copy immediately.
 * 
 * @copyright	Copyright (c) 2009-2010 TIG Corporation (http://www.tig.vn)
 * @license		http://www.gnu.org/licenses/gpl-2.0.txt GNU GENERAL PUBLIC LICENSE Version 2
 * @version 	$Id: list.phtml 4182 2010-08-01 16:27:10Z huuphuoc $
 * @since		2.0.0
 */
?>
<?php
$this->headTitle($this->translator('client_list_client_title'));
?>

<div id="r-heading">
    <img src="<?php echo $this->APP_STATIC_SERVER . '/skins/admin/default/images/client.png'; ?>" alt=""/>
    <span><?php echo $this->translator('client_list_breadcrumb'); ?></span>
    <input type="button" id="btnCreate" class="button" value="<?php echo $this->translate('client_list_add'); ?>" onclick="location = '<?php echo $this->url(array(), 'ad_client_add'); ?>';"/>
</div>

<!-- Search form -->
<form method="post" action="<?php echo $this->url(array(), 'ad_client_list'); ?>">
    <div id="filters">
        <div class="f-data">
            <label><?php echo $this->translator('client_list_search_name'); ?>:</label>
            <input type="text" style="width: 180px" name="name" value="<?php if (isset($this->exp['name'])) : ?><?php echo $this->exp['name']; ?><?php endif; ?>" />   
        </div>
        <div class="f-data">
            <label><?php echo $this->translator('client_list_search_email'); ?>:</label>
            <input type="text" style="width: 180px" name="email" value="<?php if (isset($this->exp['email'])) : ?><?php echo $this->exp['email']; ?><?php endif; ?>" />
        </div>
        <div class="f-data">
            <label><?php echo $this->translator('client_list_search_address'); ?>:</label>
            <input type="text" style="width: 180px" name="address" value="<?php if (isset($this->exp['address'])) : ?><?php echo $this->exp['address']; ?><?php endif; ?>" />
        </div>
        <div class="f-submit">
            <input type="submit" class="button" value="<?php echo $this->translator('client_list_search_button') ?>"/>
        </div>
    </div>    
</form>

<!-- List of clients -->
<table class="list" cellspacing="0">
    <thead>
        <tr>
            <td width="3%">
                <input type="checkbox" class="chkAll"/>
            </td>
            <td width="15%">
                <?php echo $this->translator('client_list_name'); ?>
            </td>
            <td width="25%">
                <?php echo $this->translator('client_list_email'); ?>
            </td>
            <td width="15%">
                <?php echo $this->translator('client_list_telephone'); ?>
            </td>
            <td width="30%">
                <?php echo $this->translate('client_list_address'); ?>
            </td>
            <td width="10%">
                <?php echo $this->translate('client_list_action'); ?>
            </td>
        </tr>
    </thead>
    <tbody>
        <?php if ($this->numClients == 0) : ?>
        <tr><td colspan ="6" style="color: #fc0202;"><?php echo $this->translator('client_list_not_found'); ?></td></tr>
        <?php else : ?>
            <?php
            $i=0;
            foreach ($this->clients as $client) : 
                $class= 'class="'. (($i == $this->numzones - 1) ? 'last' : '')  . '"';
            ?>
        <tr id="client-<?php echo $client->id?>" <?php echo $class ?>>
            <td>
                <input type="checkbox" class="chkId" value="<?php echo $client->id;?>"/>
            </td>
            <td><?php echo $client->name ?></td>
            <td><?php echo $client->email ?></td>
            <td><?php echo $client->telephone ?></td>
            <td><?php echo $client->address ?></td>
            <td>
                <?php if ($this->allow('edit')) : ?>
                    <a href="<?php echo $this->url(array('id' => $client->id), 'ad_client_edit'); ?>"><?php echo $this->translator('client_list_edit_action'); ?></a>
                    <?php endif; ?>
                    |
                    <?php if ($this->allow('delete')) : ?> 
                    <a href="javascript: void(0);" rel="<?php echo $client->id; ?>" class="deleteAction"><?php echo $this->translator('client_list_delete_action'); ?></a>
                    <?php endif; ?>
            </td>
        </tr>
            <?php
            $i++;
            endforeach;?>
        <?php endif;?>
    </tbody>
    <tfoot>
        <tr>
            <td width="3%">
                <input type="checkbox" class="chkAll"/>
            </td>
            <td width="15%">
                <?php echo $this->translator('client_list_name'); ?>
            </td>
            <td width="25%">
                <?php echo $this->translator('client_list_email'); ?>
            </td>
            <td width="15%">
                <?php echo $this->translator('client_list_telephone'); ?>
            </td>
            <td width="30%">
                <?php echo $this->translate('client_list_address'); ?>
            </td>
            <td width="10%">
                <?php echo $this->translate('client_list_action'); ?>
            </td>
        </tr>
    </tfoot>
</table>
<div id="pagination">
        <?php echo $this->paginator()->slide($this->paginator, $this->paginatorOptions); ?>
</div>    


<script type="text/javascript">
    $(document).ready(function() {
    <?php if ($this->allow('delete')) : ?>
        $('.deleteAction').click(function() {
            var self = this;
            if(confirm('<?php echo addslashes($this->translator('client_list_delete_confirm')); ?>')){
                $(self).html('').addClass('a_ui_helper_loading');
                            $.ajax({
                                url: '<?php echo $this->url(array(), 'ad_client_delete'); ?>',
                                type: 'POST',
                                data: { id: $(self).attr('rel') },
                                success: function(response) {
                                    $('#client-' + $(self).attr('rel')).fadeOut('slow');
                                }
                            });
            }
       });
    <?php endif; ?>
    });
</script>
